package com._520it.crm.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com._520it.crm.domain.Owner;
import com._520it.crm.service.IOwnerService;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class OwnerController {
	@Autowired
	private IOwnerService service;
	@RequestMapping("/owner/index")
	public String index(){
		return "owner/index";
	}



	@RequestMapping("/owner_selectAll")
	@ResponseBody
	public List<Owner> selectAll(){
		return service.selectAll();
	}


	@RequestMapping("/owner/list/view")
	public ModelAndView listView(
			@RequestParam(defaultValue = "1") int current,
			@RequestParam(defaultValue = "10") int size,
			String name,
			String nature,
			String papersType,
			String papersNum,
			ModelAndView modelAndView){
		modelAndView.setViewName("owner/list");
		List<Owner> OwnerList = service.selectPage(current,size,name,nature,papersType,papersNum);

		modelAndView.addObject("list",OwnerList);
		int count = service.selectPageCount(name,nature,papersType,papersNum);
		int totalCount = count%size==0?count/size:count/size+1;
		modelAndView.addObject("totalCount",totalCount);
		modelAndView.addObject("current",current);
		return modelAndView;
	}
}
